package cn.itcast.service.impl;

import cn.itcast.dao.RoleDao;
import cn.itcast.entity.PageResult;
import cn.itcast.pojo.Role;
import cn.itcast.pojo.User;
import cn.itcast.service.RoleService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Set;

@Service
@Slf4j
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDao roleDao;

    @Override
    public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
        log.info("------RoleServiceImpl------pageQuery------传递到实现类的分页参数------当前" + currentPage + "页," + "每页展示" + pageSize + "条," + "查询条件为:" + queryString);
        PageHelper.startPage(currentPage, pageSize);
        Page<User> page = roleDao.findByCondition(queryString);
        log.info("------RoleServiceImpl------pageQuery------查询到的分页对象信息page------" + page);
        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public List<Role> findAll() {
        return roleDao.findAll();
    }

    //根据角色得到菜单ID
    @Override
    public Integer[] findIdByMenu(Integer roleId) {

        return roleDao.findIdByMenu(roleId);
    }


}
